package com.lagou.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lagou.common.pojo.Goods;
import com.lagou.common.pojo.GoodsVo;
import com.lagou.goods.mapper.GoodsMapper;
import com.lagou.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.management.relation.Relation;
import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;
    @Override
    public Goods queryById(Integer id) {
        return goodsMapper.selectById(id);
    }

    @Override
    public int deleteById(Integer id) {
        return goodsMapper.deleteById(id);
    }

    @Override
    public int updateById(Goods goods) {
        return goodsMapper.updateById(goods);
    }

    @Override
    public GoodsVo queryList(Integer current, Integer size) {
        GoodsVo goodsVo=new GoodsVo();
        IPage<Goods> page = new Page<>(current, size);
        goodsMapper.selectPage(page,null);
        goodsVo.setCurrent(current);
        goodsVo.setSize(size);
        goodsVo.setTotal(page.getTotal());
        goodsVo.setGoodsList(page.getRecords());
        return goodsVo;

    }



}
